package dal

import (
	"Metro/config"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"gorm.io/gorm/logger"
	"runtime"
)

var DB *gorm.DB

func init() {
	var err error
	dsn := config.DSN
	DB, err = gorm.Open(mysql.Open(dsn), &gorm.Config{
		Logger: logger.Default.LogMode(logger.Silent), // 开启日志模式，打印 SQL
	})
	//DB = DB.Debug()

	if err != nil {
		panic(err)
	}
	sqlDB, _ := DB.DB()
	if err != nil {
		panic(err)
	}
	sqlDB.SetMaxOpenConns(runtime.NumCPU() * 2)
	sqlDB.SetMaxIdleConns(runtime.NumCPU())
}
